
$(document).ready(function() {
	$('#list-films').masonry({
		isAnimated: true
	});

	$('#list-films-bis').masonry({
		isAnimated: true
	});

	displayPlace();

	$('.place').not('.selected').bind('click', function(){
		var that = $(this);

		$.post('/reservations/add',{
			user_id: $('#user_id').val(),
			seance_id: $('#seance_id').val(),
			place: $(this).children('p').html()
		}, function(data){
			if(data.error == 0)
			{
				$('.place').removeClass('user');
				that.addClass('user');
				displayPlace();
			}

			if(data.error == 2)
			{
				$('.place').removeClass('user');
				displayPlace();
			}
		}, 'json');
	});

	function displayPlace(){
		if($('.user').length > 0)
		{
			$('.siege').html(' - Siège ' + $('.user p').html());
			$('.siege').parent().css('margin-left', '-55px');
		}
		else
		{
			$('.siege').html('');
			$('.siege').parent().css('margin-left', '-35px');
		}
	}

	$('#datepicker').datetimepicker({
		language: 'en',
		pick12HourFormat: false,
		pickSeconds: false
	});
	
	
});